<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=latin1">
        <link rel="stylesheet" type="text/css" href="../padrao.css" />
        <link rel="stylesheet" href="../jQuery/lista.css" type="text/css" media="all" />
        <script type="text/javascript" src="../jQuery/jquery-1.2.1.pack.js"></script>
        <script type="text/javascript" src="../jQuery/busca.js"></script>
        <script type="text/javascript" src="../sorttable.js"></script>
        <script type="text/javascript">
            function ChangeColor(tableRow, highLight)
            {
                if (highLight)
                {
                    tableRow.style = '#dcfac9';
                }
                else
                {
                    tableRow.style.backgroundColor = 'white';
                }
            }

            function vai(placa)
            {
                document.location.href = "view_caminhao.php?caminhao_selecionado="+placa;
            }
        </script>

        <title> Pesquisa de Empresas </title>

        <?php
        include '../infobox.php';
        include '../verifica_usuario.php';
        include '../functions.php';
        include '../functions_office.php';
        include '../menu.php';
        ?>

    </head>
    <body>
        <div class="conteudo">
            <p class="titulopesquisa" align='center'> CAMINHOES </p>


            <?php
            $orderby = $_GET[orderby];
            if($orderby == ""){
                $orderby = "EMPRESAS_cpf_cnpj";
            }
            include("mysqlconfig.inc");
            $query = "select * from CAMINHOES
                      ORDER BY $orderby ASC; ";


            $res = mysql_query($query);
            $num_reg = mysql_num_rows($res);
            echo "<table> ";
            echo "<tr class='titulo'>";
            echo "<td> <a href='?orderby=placa'> Placa </td>";
            echo "<td> <a href='?orderby=tipo'>Tipo </td>";
            echo "<td> <a href='?orderby=EMPRESAS_nome'> Empresa </td>";
            echo "<td> <a href='?orderby=EMPRESAS_cpf_cnpj'>CPF/CNPJ </td>";
            echo "<td> <a href='?orderby=modelo'>Modelo </td>";
            echo "<td> <a href='?orderby=cor'> Cor </td>";
            echo "<td> <a href='?orderby=marca'> Marca </td>";
            echo "</tr>";

            for ($i = 0; $i < $num_reg; $i++) {
                $mostra = mysql_fetch_array($res);
                $placa = $mostra[placa];
                if ($i % 2 == 1) {
                    $tipolinha = "tipo1";
                } else {
                    $tipolinha = "tipo2";
                }
                echo "<tr class='$tipolinha'
                       onmouseover='ChangeColor(this, true)'
                       onmouseout='ChangeColor(this, false);'
                       onclick='vai(\"".$placa."\")'>
                ";
                echo "<td> $mostra[placa] </td>";
                echo "<td> $mostra[tipo] </td>";
                echo "<td> $mostra[EMPRESAS_nome] </td>";
                echo "<td> $mostra[EMPRESAS_cpf_cnpj] </td>";
                echo "<td> $mostra[modelo] </td>";
                echo "<td> $mostra[cor] </td>";
                echo "<td> $mostra[marca] </td>";
                echo "</tr>";
            }
            echo "</form>";
            echo "</table>";
            echo "$num_reg Caminhoes cadastrados <br>";
            mysql_close($con);

            //troca ordenaçao
            if($ordem == "ASC"){
              $ordem = "DESC";
              $_SESSION[ordem] = $ordem;
            }else {
                $ordem = "ASC";
              $_SESSION[ordem] = $ordem;
            }
            ?>
        </div>
    </body>
</html>